package ibmetp.mis.file;

import ibmetp.mis.vo.User;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
 * 读取Excel文件
 * @author LAN DABIN
 * @created 2011-10-1
 *
 */
public class ExcelHandler {
	
	public static List<User> readInputStream(InputStream in)
	{
		//FileInputStream fStream=new FileInputStream(in);
		HSSFWorkbook wb;
		List<User> list=new ArrayList();
		try {
	    wb = new HSSFWorkbook(in);		
		HSSFSheet sheet = wb.getSheetAt(0);
		HSSFRow row;
	//	String cell;
		User user=null;
		
		for (int i = sheet.getFirstRowNum(); i < sheet
				.getPhysicalNumberOfRows(); i++) {
			   row = sheet.getRow(i);
			 user=new User();
			for (short j = 0; j <=3;//row.getPhysicalNumberOfCells(); 
			 j++) {	
				if(row.getCell(j)!=null){
			 if(j==0)
			 user.setUserNo(row.getCell(j).getStringCellValue().trim());
			 if(j==1)
		     user.setUserName(row.getCell(j).getStringCellValue().trim());
			 if(j==2)
			 user.setEmail(row.getCell(j).getStringCellValue().trim());
			 if(j==3)
				 user.setDescript(row.getCell(j).getStringCellValue().trim());			
				}
			}
			System.out.println("ExcelHandler.java:"+user);
			list.add(user);			
	}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;

	}
}
